﻿@model Adams.Public.DataTransfer.Web.Areas.Membership.Donations.Index.PageLoad
@{
    Layout = "~/Views/Shared/_MembershipLayout.cshtml";
}
@section Head{
}
<h1>
    My Donations</h1>
@if (!string.IsNullOrEmpty(Request["msg"]))
{
    if (Request["msg"] == "1")
    {
    <div class="ui-state-highlight">
        Your Donation has been canceled</div>
    }
    else
    {
    <div class="ui-state-error">
        Unable to cancel donation</div>
    }
}
<br />
<a href="/MyAdams/Donations/Donate">Click here to make a donation</a>
<br />
<br />
<h2>
    My One-Time Donations</h2>
<table class="data" cellspacing="0">
    <tr>
        <th>
            Donated On
        </th>
        <th>
            Amount
        </th>
        <th>
            To
        </th>
        <th>
            Status
        </th>
        <th>
        </th>
    </tr>
    @if (Model.OneTimes.Count == 0)
    {
        <tr>
            <td colspan="10">
                You have no donations.
            </td>
        </tr>
    }
    @foreach (var onetime in Model.OneTimes)
    {
        <tr>
            <td>@onetime.EnteredOn.ToShortDateString()
            </td>
            <td>
                @string.Format("{0:C}", onetime.Amount)
            </td>
            <td>
                @onetime.Bucket.Name
            </td>
            <td>
                @if (onetime.Status == Adams.Shared.Entities.Donations.Status.NotConfirmed)
                {
                    <text>Not confirmed</text>
                }
                else if (onetime.Status == Adams.Shared.Entities.Donations.Status.Pending)
                {
                    <text>Pending</text>
                }
                else if (onetime.Status == Adams.Shared.Entities.Donations.Status.Complete)
                {
                    <text>Complete</text>
                }
                else if (onetime.Status == Adams.Shared.Entities.Donations.Status.Canceled)
                {
                    <text>Canceled</text>
                }
                else if (onetime.Status == Adams.Shared.Entities.Donations.Status.Failed)
                {
                    <text>Failed</text>
                }
                else
                {
                    <text>Unknown</text>
                }
            </td>
            <td>
                @if (onetime.Status == Adams.Shared.Entities.Donations.Status.Pending)
                {
                    <a href="#" class="cancelonetime" did="@onetime.ID">Cancel</a>
                }
            </td>
        </tr>
    }
</table>
<h2>
    My Recurring Donations</h2>
<table class="data" cellspacing="0">
    <tr>
        <th>
            Last processed On
        </th>
        <th>
            Next process On
        </th>
        <th>
            Amount
        </th>
        <th>
            To
        </th>
        <th>
            Status
        </th>
        <th>
        </th>
    </tr>
    @if (Model.Recurrings.Count == 0)
    {
        <tr>
            <td colspan="10">
                You have no recurring donations.
            </td>
        </tr>
    }
    @foreach (var recurring in Model.Recurrings)
    {
        <tr>
            <td>
                @(Adams.Shared.DateHelper.DiffDays(recurring.LastProcessedOn, DateTime.MinValue) == 0 ? "never" : recurring.LastProcessedOn.ToShortDateString())
            </td>
            <td>
                @recurring.NextProcessOn.ToShortDateString()
            </td>
            <td>
                @string.Format("{0:C}", recurring.Amount)
            </td>
            <td>
                @recurring.Bucket.Name
            </td>
            <td>
                @if (recurring.Status == Adams.Shared.Entities.Donations.Status.NotConfirmed)
                {
                    <text>Not confirmed</text>
                }
                else if (recurring.Status == Adams.Shared.Entities.Donations.Status.Pending)
                {
                    <text>Pending</text>
                }
                else if (recurring.Status == Adams.Shared.Entities.Donations.Status.Complete)
                {
                    <text>Complete</text>
                }
                else if (recurring.Status == Adams.Shared.Entities.Donations.Status.Canceled)
                {
                    <text>Canceled</text>
                }
                else if (recurring.Status == Adams.Shared.Entities.Donations.Status.Failed)
                {
                    <text>Failed</text>
                }
                else
                {
                    <text>Unknown</text>
                }
            </td>
            <td>
                @if (recurring.Status == Adams.Shared.Entities.Donations.Status.Pending || 
                    recurring.Status == Adams.Shared.Entities.Donations.Status.Complete || 
                    recurring.Status == Adams.Shared.Entities.Donations.Status.Failed)
                {
                    <a href="#" class="cancelrecurring" did="@recurring.ID">Cancel</a>
                }
            </td>
        </tr>
    }
</table>
@section Scripts {
    <script src="/Areas/Membership/Scripts/Donations/donate.js" type="text/javascript"></script>
}
